<?php
/** 
 * 权限分组模型基类
 *
 * @author   xionggan
 * @date     2019-09-20
 */

namespace app\common\model;

use think\Db;
use think\Model;

class AuthGroup extends Model
{
    protected $name  = 'auth_group';
    protected $error = null;
    protected $append = [
        'status_text',
        'rules_array',
    ];

    const STATUS_0  = 0;
    const STATUS_1  = 1;
 
    /**
     * 获取状态映射
     * @return  array   状态映射表
     */
    public function getStatusMap()
    {
        return [
            self::STATUS_0  => '禁用',
            self::STATUS_1  => '正常',
        ];
    }
    
    public function getStatusTextAttr($value, $data)
    {
        $map = $this->getStatusMap();
        return $map[$data['status']] ?? '';
    }

    public function getRulesArrayAttr($value, $data)
    {
        if (empty($data['rules'])) {
            return [];
        }
        return explode(',', $data['rules']);
    }

    public function getCreateTimeAttr($value, $data)
    {
        return empty($data['create_time']) ? '' : date('Y-m-d H:i:s', $data['create_time']);
    }
    
}
